Special:Log and the logging table -- unified logging scariness!
[lhc/web/wiklou.git] / includes / LogPage.php
1 <?php
2 #$Id$
3 #
4 # Copyright (C) 2002, 2004 Brion Vibber <brion@pobox.com>
5 # http://www.mediawiki.org/
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 # http://www.gnu.org/copyleft/gpl.html
21
22 # Class to simplify the use of log pages.
23 # The logs are now kept in a table which is easier to manage and trim
24 # than ever-growing wiki pages.
25
26 class LogPage {
27 /* private */ var $type, $action, $comment;
28 var $updateRecentChanges = true;
29
30 function LogPage( $type ) {
31 # Type is one of 'block', 'protect', 'rights', 'delete', 'upload'
32 $this->type = $type;
33 }
34
35 function saveContent() {
36 if( wfReadOnly() ) return;
37
38 global $wgUser;
39 $fname = 'LogPage::saveContent';
40
41 $dbw =& wfGetDB( DB_MASTER );
42 $uid = $wgUser->getID();
43
44 $this->timestamp = $now = wfTimestampNow();
45 $dbw->insertArray( 'logging',
46 array(
47 'log_type' => $this->type,
48 'log_action' => $this->action,
49 'log_timestamp' => $dbw->timestamp( $now ),
50 'log_user' => $uid,
51 'log_namespace' => $this->target->getNamespace(),
52 'log_title' => $this->target->getDBkey(),
53 'log_comment' => $this->comment
54 ), $fname
55 );
56
57 # And update recentchanges
58 if ( $this->updateRecentChanges ) {
59 $rcComment = $this->actionText;
60 if( '' != $this->comment ) {
61 $rcComment .= ': ' . $this->comment;
62 }
63 $titleObj = Title::makeTitle( NS_SPECIAL, 'Log/' . $this->type );
64 RecentChange::notifyLog( $now, $titleObj, $wgUser, $rcComment );
65 }
66 return true;
67 }
68
69 /* static */ function actionText( $type, $action, $titleLink ) {
70 static $actions = array(
71 'block/block' => 'blocklogentry',
72 'block/unblock' => 'blocklogentry',
73 'protect/protect' => 'protectedarticle',
74 'protect/unprotect' => 'unprotectedarticle',
75 'rights/rights' => 'bureaucratlogentry',
76 'delete/delete' => 'deletedarticle',
77 'delete/restore' => 'undeletedarticle',
78 'upload/upload' => 'uploadedimage',
79 'upload/revert' => 'uploadedimage',
80 );
81 $key = "$type/$action";
82 if( isset( $actions[$key] ) ) {
83 return wfMsg( $actions[$key], $titleLink );
84 } else {
85 wfDebug( "LogPage::actionText - unknown action $key\n" );
86 return "$action $titleLink";
87 }
88 }
89
90 function addEntry( $action, &$target, $comment ) {
91 global $wgLang, $wgUser;
92
93 $this->action = $action;
94 $this->target =& $target;
95 $this->comment = $comment;
96 $this->actionText = LogPage::actionText( $this->type, $action,
97 $target->getPrefixedText() );
98
99 return $this->saveContent();
100 }
101 }
102
103 ?>